package erik.ds.btree;

public class BinaryTree<T> {

	public BinaryTree() {
		root = null;
	}
	
	public BinaryTree(T rootItem) {
		root = new BinaryNode<T>(rootItem, null, null);
	}
	
	public int size() {
		return BinaryNode.size(root);
	}
	
	public int height() {
		return BinaryNode.height(root);
	}
	
	public void printPreOrder() {
		if (root != null)
			root.printPreOrder();
	}
	
	public void printPostOrder() {
		if (root != null)
			root.printPostOrder();
	}
	
	public void printInOrder() {
		if (root != null)
			root.printInOrder();
	}
	
	public void makeEmpty() {
		root = null;
	}
	public boolean isEmpty() {
		return root == null;
	}
	
	public void merge(T rootItem, BinaryTree<T> t1, BinaryTree<T> t2) {
		if (t1.root == t2.root && t1.root != null) {
			throw new IllegalArgumentException();
		}
		
		root = new BinaryNode<T>(rootItem, t1.root, t2.root);
		if (this != t1) 
			t1.root = null;
		if (this != t2)
			t2.root = null;
	}
	
	public BinaryNode<T> getRoot() {
		return root;
	}
	
	public void setRoot(BinaryNode<T> root) {
		this.root = root;
	}
	
	private BinaryNode<T> root;
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}


}
